package com.own.business.login.phone.core.form;

import com.own.component.common.exception.BusinessSimpleException;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * LoginForm
 *
 * @author chenxueli
 * @date 2023-06-21 15:52:40
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class LoginPhoneForm implements Serializable {

    @Schema(title = "手机号")
    private String phone;

    @Schema(title = "客户端id", hidden = true)
    private String clientId;

    @Schema(title = "验证码")
    private String code;

    @Schema(title = "加密秘钥字段key")
    private String key;

    @Schema(title = "登录的ip", hidden = true)
    private String ip;

    @Schema(title = "是否同步注册", hidden = true)
    private Boolean register;

    @Schema(title = "密码", description = "使用和手机号一样的加密方式")
    private String password;

    @Schema(title = "账号类型 1=普通用户 2=管理员", hidden = true)
    private Integer type;

    public void init() {
        if (type == null) {
            type = 1;
        }
    }

    public void check() {
        init();
        if (StringUtils.isBlank(phone)) {
            throw new BusinessSimpleException("手机号不能为空");
        }
    }

}
